package com.xy.blog.user.dao.impl;

import com.xy.blog.core.dao.IBaseCommonDao;
import com.xy.blog.core.exception.BaseException;
import com.xy.blog.core.springmvc.result.page.PageReq;
import com.xy.blog.core.springmvc.result.page.PageResp;
import com.xy.blog.user.controller.model.req.query.UserAttrQuery;
import com.xy.blog.user.dao.IUserAttrRelDao;
import com.xy.blog.user.dao.mapper.rel.UserAttrRelMapper;
import com.xy.blog.user.dao.model.rel.UserAttrDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zanhonglei
 * @version V1.0
 * @Description:
 * @date 2020/3/13
 */
@Repository
public class UserAttrRelDaoImpl implements IBaseCommonDao<UserAttrDO, UserAttrQuery>, IUserAttrRelDao {

    @Autowired
    private UserAttrRelMapper userAttrRelMapper;


    @Override
    public List<UserAttrDO> select(UserAttrDO item) {
        return userAttrRelMapper.select(item);
    }

    @Override
    public int selectCount(UserAttrDO item) {
        return userAttrRelMapper.selectCount(item);
    }

    @Override
    @Deprecated
    public PageResp<UserAttrDO> listByPage(PageReq<UserAttrQuery> req) throws BaseException {
        return null;
    }

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public void save(UserAttrDO item) throws BaseException {
        userAttrRelMapper.insert(item);
    }

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public void updateById(UserAttrDO item) throws BaseException {
        userAttrRelMapper.updateByPrimaryKeySelective(item);
    }

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public void deleteById(Long id) throws BaseException {
        userAttrRelMapper.deleteByPrimaryKey(id);
    }

    @Override
    public UserAttrDO getById(Long id) throws BaseException {
        return userAttrRelMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public void deleteByUserId(Long id) throws BaseException {
        UserAttrDO userAttrDO = new UserAttrDO();
        userAttrDO.setUserId(id);
        userAttrRelMapper.delete(userAttrDO);
    }

    @Override
    public List<UserAttrDO> getByUserId(Long id) {
        UserAttrDO userAttrDO = new UserAttrDO();
        userAttrDO.setUserId(id);
        return userAttrRelMapper.select(userAttrDO);
    }
}
